From fe6507f8756bacb328aaab7714c589b1c44628b5 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 21 Jun 2019 03:41:25 +0000 Subject: [PATCH] Add a test for gtk_widget_insert_action_group This tests that action group inheritance behaves as expected. --- testsuite/gtk/action.c | 111 ++++++++++++++++++++++++++++++++++++++ testsuite/gtk/meson.build | 3 +- 2 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 testsuite/gtk/action.c diff --git a/testsuite/gtk/action.c b/testsuite/gtk/action.c new file mode 100644 index 0000000000..f0840b279a --- /dev/null +++ b/testsuite/gtk/action.c @@ -0,0 +1,111 @@ +/* Copyright (C) 2019 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ +#include + +static int win_activated; +static int box_activated; + +static void +win_activate (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) +{ + win_activated++; +} + +static void +box_activate (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) +{ + box_activated++; +} + +static void +test_action (void) +{ + GtkWidget *window; + GtkWidget *box; + GtkWidget *button; + GSimpleActionGroup *win_actions; + GSimpleActionGroup *box_actions; + GActionEntry win_entries[] = { + { "action", win_activate, NULL, NULL, NULL }, + }; + GActionEntry box_entries[] = { + { "action", box_activate, NULL, NULL, NULL }, + }; + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); + button = gtk_button_new (); + + gtk_container_add (GTK_CONTAINER (window), box); + gtk_container_add (GTK_CONTAINER (box), button); + + win_actions = g_simple_action_group_new (); + g_action_map_add_action_entries (G_ACTION_MAP (win_actions), + win_entries, + G_N_ELEMENTS (win_entries), + NULL); + + box_actions = g_simple_action_group_new (); + g_action_map_add_action_entries (G_ACTION_MAP (box_actions), + box_entries, + G_N_ELEMENTS (box_entries), + NULL); + + gtk_widget_insert_action_group (window, "win", G_ACTION_GROUP (win_actions)); + gtk_widget_insert_action_group (box, "box", G_ACTION_GROUP (box_actions)); + + g_assert_cmpint (win_activated, ==, 0); + g_assert_cmpint (box_activated, ==, 0); + + gtk_widget_activate_action (button, "win.action", NULL); + + g_assert_cmpint (win_activated, ==, 1); + g_assert_cmpint (box_activated, ==, 0); + + gtk_widget_activate_action (box, "win.action", NULL); + + g_assert_cmpint (win_activated, ==, 2); + g_assert_cmpint (box_activated, ==, 0); + + gtk_widget_activate_action (button, "box.action", NULL); + + g_assert_cmpint (win_activated, ==, 2); + g_assert_cmpint (box_activated, ==, 1); + + gtk_widget_activate_action (window, "box.action", NULL); + + g_assert_cmpint (win_activated, ==, 2); + g_assert_cmpint (box_activated, ==, 1); + + gtk_widget_destroy (window); + g_object_unref (win_actions); + g_object_unref (box_actions); +} + +int +main (int argc, + char *argv[]) +{ + gtk_test_init (&argc, &argv); + + g_test_add_func ("/action/inheritance", test_action); + + return g_test_run(); +} diff --git a/testsuite/gtk/meson.build b/testsuite/gtk/meson.build index d3a4ea13f0..88016781ed 100644 --- a/testsuite/gtk/meson.build +++ b/testsuite/gtk/meson.build @@ -8,9 +8,9 @@ if cc.get_id() != 'msvc' endif tests = [ - ['popover'], ['accel'], ['accessible'], + ['action'], ['adjustment'], ['bitmask', ['../../gtk/gtkallocatedbitmask.c'], ['-DGTK_COMPILATION', '-UG_ENABLE_DEBUG']], ['builder', [], [], gtk_tests_export_dynamic_ldflag], @@ -39,6 +39,7 @@ tests = [ ['object'], ['objects-finalize'], ['papersize'], + ['popover'], ['propertylookuplistmodel', ['../../gtk/gtkpropertylookuplistmodel.c'], ['-DGTK_COMPILATION', '-UG_ENABLE_DEBUG']], ['rbtree', ['../../gtk/gtktreerbtree.c'], ['-DGTK_COMPILATION', '-UG_ENABLE_DEBUG']], ['recentmanager'], -- 2.30.2